package com.zk.zhikaoyun.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2   //开启swagger的接口扫描及API文档生成
public class Swagger2Config {

    //Docket对象，用于封装API文档信息
    @Bean
    public Docket getDocket() {

        Contact contact =
                new Contact("千锋阿丁", "http://www.qfedu.com", "ading@1000phone.com");

        ApiInfoBuilder builder = new ApiInfoBuilder();
        builder.title("《智云在线考试系统》API文档")                            //指定标题
                .description("此文档对智云在线考试系统中的后端接口进行详细的API说明")   //文档描述信息
                .version("v 2.0.1")                                           //指定当前文档的版本
                .contact(contact);                                            //联系人信息

        //ApiInfo对象用来封装生成文档的封面信息（文档标题、版本、作者等信息）
        ApiInfo apiInfo = builder.build();

        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.....controller"))
                .paths(PathSelectors.any())
                .build();

        return docket;
    }

}